
dislikes.initDefault = function(context, reset)
{
	dislikes.userID = null;
	dislikes.userLoc = null;
	dislikes.usersData = {};
	dislikes.totalElements = 1;
	dislikes.options = {};
	dislikes.friendsData = [];
	
	if(reset) {
		dislikes.resetSession();
	}
};

dislikes.resetSession = function(context) {
	if(context == undefined) context = document;
	
	dislikes.processRequest({action:'stateChanged', loggedIn: false, callback: ''}, '', context);
};

dislikes.getNotifications = function(context) {
	if(context == undefined) context = document;
	
	dislikes.processRequest({action:'getNotifications', callback: 'dislikes.processNotifications'}, dislikes.processNotifications, context);
	setTimeout("dislikes.getNotifications();", 5000);
};

dislikes.initDefault(document);

dislikes.OnPreNodeInserted = function(context, lastCount)
{
	if(context == undefined) context = document;
	
	var $ = dislikes.jQuery;
	
	context.isChecking = true;
	
	var thisCount = dislikes.jQuery('body', context).find('input[name="feedback_params"][isProcessed!=1],input[name="message_id"][isProcessed!=1],span[class*="comment_like_"][isProcessed!=1],#pagelet_nav_stats,#pagelet_pages_stats,#pagelet_above_html[isProcessed!=1]').length;
	
	if(typeof lastCount == 'undefined')
		var lastCount = 0;
	
	if(thisCount == lastCount)
	{
		context.isChecking = false;
		delete context.isChecking;
		
		if(thisCount != 0)
			dislikes.OnNodeInserted(context);
	}
	else
	{
		setTimeout(function() { dislikes.OnPreNodeInserted(context, thisCount); }, 750);
	}
};

dislikes.OnNodeInserted = function(context)
{
	if(context == undefined) context = document;
	
	var $ = dislikes.jQuery;
	
	var elArr = dislikes.jQuery('body', context).find('input[name="feedback_params"][isProcessed!=1],input[name="message_id"][isProcessed!=1],span[class*="comment_like_"][isProcessed!=1],#pagelet_nav_stats,#pagelet_pages_stats,#pagelet_above_html[isProcessed!=1]');
	elArr.attr('isProcessed', 1);
	
	var procArr = [];
	var procArrGrp = [];
	var procArrComm = [];
	var procArrGrpComm = [];
	var procPagesLike = [];
	
	if(elArr.length > 0)
	{
		dislikes.jQuery(elArr).each(function()
		{
			try
			{	
				if(dislikes.jQuery(this).attr('id') == 'pagelet_above_html')
				{
					if(dislikes.jQuery('#dislikeMainButton', context).length > 0)
						return;
					
					var disArr = dislikes.jQuery('#page_dislike_count', context).attr('currentIDS');
					
					var classAdd = 'hidden_elem ';
					var text = '';
					
					if(disArr != undefined)
					{
						var checkArr = disArr.split(',');
						if(dislikes.jQuery.inArray(dislikes.userID, checkArr) == -1)
						{
							var text = dislikes.getMessage('DislikeThis');
							var classAdd = '';
						}
						else
						{
							var text = dislikes.getMessage('NotDislikeThis');
							var classAdd = '';
						}
					}
					
					var el = $('<label>', context).addClass(classAdd+'mlm mainButton uiButton').attr('id', "dislikeMainButton")
										.append($('<img />', context).addClass('img').css({"width": "15px", "display": "inline-block", "height": "11px"}).attr('src', dislikes.getURL("icon14.png")))
										.append($('<input>', context).attr('type', 'button').css({"margin-left": "5px"}).val(text).attr("id", "dislike_page_button"));
					
					dislikes.jQuery('.profileHeaderMain > .fbProfileByline', context).before(el);
					
					dislikes.jQuery('#dislikeMainButton', context).click(function()
					{
						dislikes.addPageVote(context);					
					});
					
					
					return;
				}				
				else if(dislikes.jQuery(this).attr('id') == 'pagelet_nav_stats' || dislikes.jQuery(this).attr('id') == 'pagelet_pages_stats')
				{
					if(dislikes.jQuery('#page_dislike_count', context).length > 0)
						return;
					
					var tmpData = dislikes.jQuery('#pagelet_main_column', context).attr('data-gt');
					
					if(tmpData.indexOf('{') == 0)
					{
						var tmpData = JSON.parse(tmpData);
						
						if(typeof tmpData.profile_owner == 'undefined')
							return;
						
						var appid = 'page_'+tmpData.profile_owner; 
						
						dislikes.jQuery(this).append($('<div>', context).addClass('pbs placePageStats'));
						
						var el = $('<div>', context).text(dislikes.getMessage('PeopleDislikeThis'))
										.prepend($('<div>', context)
											.append($('<span>', context).attr("id", "page_dislike_count").addClass("uiNumberGiant fsxxl fwb")));
						
						dislikes.jQuery(this).children('div:last').addClass('hidden_elem').html(el);
						dislikes.jQuery(this).find('#page_dislike_count').attr('pageid', appid).css('overflow', 'hidden');
						dislikes.jQuery(this).children('div:last').children().css('overflow', 'hidden');
						
						procPagesLike.push(appid);
					}
					return;
				}
				
				if(dislikes.jQuery(this).attr('class').indexOf('comment_like_') != -1)
					var tmp = dislikes.jQuery(this).children('button').val();
				else
					var tmp = dislikes.jQuery(this).val();
				
				if(typeof(tmp) == 'undefined' || tmp == 0) return;
				
				if(dislikes.jQuery(this).attr('name') == 'message_id')
				{
					tmp = tmp + '_' + dislikes.jQuery(this).siblings('input[name="gid"]').val();
					procArrGrp.push(tmp);
					var isGrp = true;
					
					dislikes.jQuery(this).closest('form').attr('isGroup', 1);
				}
				else if(dislikes.jQuery(this).attr('class').indexOf('comment_like_') != -1)
				{
					var isComment = true;
					if(dislikes.jQuery(this).closest('form').children('input[name="gid"]').length > 0)
					{
						var isGrp = true;
						tmp = 'commGrp_'+tmp + '_' + dislikes.jQuery(this).closest('form').children('input[name="gid"]').val();
						
						procArrGrpComm.push(tmp);
					}
					else if(dislikes.jQuery(this).closest('form').children('input[name="feedback_params"]').length > 0)
					{
						var paramFbid = dislikes.jQuery(this).closest('form').children('input[name="feedback_params"]').val();
						if(typeof(paramFbid) == 'undefined') return;
						var obj = JSON.parse(paramFbid);
						if(typeof(obj.target_fbid) == 'undefined') return;				
						tmp = 'comm_'+tmp+'_'+obj.target_fbid;
						
						procArrComm.push(tmp);
					}
					else
					{
						return;
					}
					
					if(dislikes.jQuery(this).parent().attr('id').indexOf('dislikeForm') != -1)
						return;
				}
				else
				{
					var obj = JSON.parse(tmp);
					var fbid = obj.target_fbid;
					
					if(typeof(fbid) == 'undefined')
						return;
					
					procArr.push(fbid);
					var isGrp = false;
					
					dislikes.jQuery(this).closest('form').attr('isGroup', 0);
				}
				
				var html = $('<span>', context).addClass("dislikeCont hidden_elem").text(' · ')
									.append($('<button>', context).addClass("dislike_link hide stat_elem as_link").attr({"title": dislikes.getMessage('DislikeDescription'), "type": "submit", "name": "dislike"})
										.append($('<span>', context).addClass("default_message").text(dislikes.getMessage('DislikeThis')))
										.append($('<span>', context).addClass("default_message").text(dislikes.getMessage('NotDislikeThis'))));
				
				if(isComment)
					dislikes.jQuery(this).parent().append(html);
				else
					dislikes.jQuery(this).parent().find('button.as_link').not('.cmnt_translate_link').first().after(html);
					
					
				
				
				dislikes.jQuery(this).parent().find('button.dislike_link').click(function(event)
				{
					dislikes.dislikeClicked(event, context);
					return false;
				});
				
				if(isGrp)
				{
					var myEl = dislikes.jQuery(this).parent().find('.mall_ufi_like:first');
				}
				else
				{
					var myEl = dislikes.jQuery(this).parent().find('.uiUfiLike:first');
				}
				
				if(isComment)
				{
					var el = $('<span>', context).addClass("dislikeCount hidden_elem").text(' · ')
									.append($('<i>', context).addClass("img").css({"width": "14px", "display": "inline-block", "height": "9px", "background-image": "url("+dislikes.getURL("icon9.png")+")", "background-repeat": "no-repeat"}))
									.append($('<a>', context).addClass("uiTooltip comment_like_button")
										.append($('<span>', context).addClass("uiTooltipHeader").css("color", "#C20000"))
										.append($('<span>', context).addClass("uiTooltipWrap bottom center centerbottom")
											.append($('<span>', context).addClass("uiTooltipText uiTooltipNoWrap"))));
					
					dislikes.jQuery(this).parent().find('.dislikeCont').after(el);
				}
				else
				{
					var el = $('<li>', context).addClass('hidden_elem ufiItem uiListItem uiListVerticalItemBorder uiDislike')
									.append($('<div>', context).addClass("UIImageBlock clearfix")
										.append($('<a>', context).addClass("UIImageBlock_Image UIImageBlock_ICON_Image").attr('tabindex', "-1")
											.append($('<label>', context).addClass("dislikeButton")
												.append($('<i>', context).addClass('img').css({"width": "20px", "height": "14px", "background-image": "url("+dislikes.getURL("icon14.png")+")", "background-repeat": "no-repeat"}))))
										.append($('<div>', context).addClass("UIImageBlock_Content UIImageBlock_ICON_Content")));
					myEl.after(el);
				}
				dislikes.jQuery(this).find('.dislikeButton').click(function(event){ dislikes.dislikeClicked(event, context); });
			
			}
			catch(e)
			{
				console.log(e);
			}
		});
		
		dislikes.nodesCount(context, procArr, procArrGrp, procArrComm, procArrGrpComm, procPagesLike);
	}
};

dislikes.showLoading = function(context)
{
	if(context == undefined) context = document;
	
	var $ = dislikes.jQuery;
	
	var el = $('<div>', context).addClass('generic_dialog pop_dialog profileBrowserDialog full_bleed')
				.append($('<div>', context).addClass('generic_dialog_popup').css({"width": "467px", "top": 100})
					.append($('<div>', context).addClass('pop_container_advanced')
						.append($('<div>', context).addClass('pop_content').attr('id', 'pop_content')
							.append($('<div>', context).addClass('dialog_loading').text(dislikes.getMessage('Loading'))))));
	
	$('#content', context).find('.generic_dialog').remove();
	$('#content', context).prepend(el);
};

dislikes.openDislikes = function(e, context)
{
	var target = dislikes.jQuery(( e.srcElement? e.srcElement : e.target));
	
	var ids = target.attr('dislikeIds');
	if (typeof ids === 'undefined' || ids === false) {
		target = target.find('[dislikeids]').first();
	}
	
	dislikes.showLoading(context);
	setTimeout(function(){
		dislikes.processRequest({action:'getJSON',type:'dislikeList', ids: target.attr('dislikeIds'), callback: 'dislikes.updateDislikeList'}, dislikes.updateDislikeList, context);
	}, 500);
};

dislikes.openMutualDislikes = function(e, context)
{
	var target = dislikes.jQuery(( e.srcElement? e.srcElement : e.target));
	
	dislikes.showLoading(context);
	setTimeout(function()
	{
		dislikes.processRequest({action:'getJSON',type:'dislikeList', ids: target.attr('dislikeIds'), callback: 'dislikes.updateDislikeList'}, dislikes.updateDislikeList, context);
	}, 500);
};

dislikes.updateDislikeList = function(data, context)
{
	if(context == undefined) context = document;
	
	var $ = dislikes.jQuery;
	
	dislikes.usersData = data.usersData;
	var idsArr = data.ids;
	
	
	var el = $('<div>', context)
				.append($('<h2>', context).addClass('dialog_title').append($('<span>').text(dislikes.getMessage('PeopleWhoDislikeThis'))))
				.append($('<div>', context).addClass('dialog_content'));
	var el2 = el.find('div.dialog_content');
	
	el2
		.append($('<div>', context).addClass('dialog_body')
			.append($('<div>', context).addClass('fbProfileBrowser')
				.append($('<div>', context).addClass('standardLayout')
					.append($('<div>', context).addClass('listView')
						.append($('<div>', context).addClass('lists')
							.append($('<div>', context).addClass('fbProfileBrowserResult hideSummary fbListOverflow').css({"overflow-y": "auto", "height": "353px"})
								.append($('<div>', context).addClass('fbProfileBrowserList fbProfileBrowserListContainer').attr('id', 'fbDislikesList'))))))));
	el2
		.append($('<div>', context).addClass('dialog_buttons clearfix')
			.append($('<label>', context).addClass('uiButton uiButtonLarge uiButtonConfirm')
				.append($('<input />', context).attr({"type": "button", "name": "close", "value": "Close"}))));
	
	var list = $('<ul>', context).addClass('uiList');
	
	$(idsArr).each(function(k,v)
	{
		list
			.append($('<li>', context).addClass('uiListItem uiListLight uiListVerticalItemBorder')
				.append($('<div>', context).addClass('UIImageBlock clearfix UIImageBlock_Entity')
					.append($('<a>', context).addClass('UIImageBlock_Image UIImageBlock_ENT_Image').attr({"href": "https://www.facebook.com/profile.php?id="+v})
						.append($('<img />', context).attr({"src": "https://graph.facebook.com/"+v+"/picture"})
							)
						)
					.append($('<div>', context).addClass('UIImageBlock_Content UIImageBlock_ENT_Content')
						.append($('<div>', context).addClass('fsl fwb fcb')
							.append($('<a>', context).attr({"href": "https://www.facebook.com/profile.php?id="+v}).text(dislikes.usersData[v]))))));
	});

	var listitems = list.children('li').css('padding', '4px').get();
	listitems.sort(function(a, b)
	{
		var compA = $(a).text().toUpperCase();
		var compB = $(b).text().toUpperCase();
		return (compA < compB) ? -1 : (compA > compB) ? 1 : 0;
	});
	
	list.html(listitems);
	
	el.find('#fbDislikesList').append(list);
	el.find('.fbListOverflow').css({"overflow-y":"auto","max-height":"353px","height":"353px" });
	el.find('.dialog_buttons').find('input').click(function(){ $(this).closest('.generic_dialog').remove(); });
	
	$('#content', context).find('.generic_dialog:first').find('.pop_content').html(el);
};

dislikes.updateOptionsDialog = function(context)
{
	if(context == undefined) context = document;
	
	var $ = dislikes.jQuery;
	
	var el = $('<div>', context)
				.append($('<h2>', context).addClass('dialog_title').append($('<span>').text('di.slik.es - '+dislikes.getMessage('Options'))))
				.append($('<div>', context).addClass('dialog_content'));
	var el2 = el.find('div.dialog_content');
	
	el2
		.append($('<div>', context).addClass('dialog_body')
			.append($('<div>', context).addClass('fbProfileBrowser')
				.append($('<div>', context).addClass('standardLayout')
					.append($('<div>', context).addClass('listView')
						.append($('<div>', context).addClass('lists')
							.append($('<div>', context).addClass('').css({"overflow-y": "auto", "height": "353px"})
								.append($('<div>', context).addClass('').attr('id', 'fbDislikesList'))))))));
	el2
		.append($('<div>', context).addClass('dialog_buttons clearfix')
			.append($('<label>', context).addClass('uiButton uiButtonLarge uiButtonConfirm')
				.append($('<input />', context).attr({"type": "button", "name": "close", "value": "Close"}))));
	
	
	
	var langSel = $('<select>', context).attr('id', "dislikes_options_language")
						.append($('<option>', context).val(0).attr('selected', 'selected').text(dislikes.getMessage('UseFacebookLanguage')));
	
	for(var loc in dislikes.trans)
	{
		langSel.append($('<option>', context).val(loc).text(dislikes.trans[loc].name));
	}
	
	var elOpt = $('<div>', context)
					.append($('<div>', context).attr('id', 'dislikesOptionsIcon')
						.append($('<img />', context).attr('src', dislikes.getURL("icon48.png"))))
					.append($('<div>', context).addClass("fbDislikeMargin")
						.append($('<label>', context).text(dislikes.getMessage('SelectLanguage')))
						.append($('<br />', context))
						.append(langSel)
						.append($('<br />', context))
						.append($('<br />', context))
						.append($('<span>', context).text(dislikes.getMessage('ReloadAfterChange'))))
					.append($('<div>', context).addClass("fbDislikeMargin")
						.append($('<label>', context).text(dislikes.getMessage('PostRandomComment')))
						.append($('<br />', context))
						.append($('<input />', context).attr({"type": "radio", "value": "1", "name": "dislikes_options_comment"}))
						.append($('<span>', context).text(dislikes.getMessage('Yes')))
						.append($('<input />', context).attr({"type": "radio", "value": "0", "name": "dislikes_options_comment"}))
						.append($('<span>', context).text(dislikes.getMessage('No'))))
					.append($('<div>', context).addClass("fbDislikeMargin")
						.append($('<table>', context).attr({"align": "center", "width": "90%", "border": 0, "cellspacing": 5, "cellpadding": 0})
							.append($('<tr>', context)
								.append($('<td>', context).attr({"width": "50%", "align": "center"})
									.append($('<form>', context).attr({"action": "https://www.paypal.com/cgi-bin/webscr", "method": "post"})
										.append($('<input />', context).attr({"type": "hidden", "name": "cmd", "value": "_s-xclick"}))
										.append($('<input />', context).attr({"type": "hidden", "name": "encrypted", "value": "-----BEGIN PKCS7-----MIIHRwYJKoZIhvcNAQcEoIIHODCCBzQCAQExggEwMIIBLAIBADCBlDCBjjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtQYXlQYWwgSW5jLjETMBEGA1UECxQKbGl2ZV9jZXJ0czERMA8GA1UEAxQIbGl2ZV9hcGkxHDAaBgkqhkiG9w0BCQEWDXJlQHBheXBhbC5jb20CAQAwDQYJKoZIhvcNAQEBBQAEgYAlRNzEdljR2rCfNPU+WoKynH6dSohvs/ZVOrB6mWTcMzs+nkbTl2z6M5EIclVXZYLcKYKGSFdxak96m9rnwf8FMqJzp/ulmBANuvVakjKdW4hSMqMGAKz2lAON5m3cJts4Xo779wSUJcN7lL/mfRxfoolst1haXcMTwMPvIM6p8TELMAkGBSsOAwIaBQAwgcQGCSqGSIb3DQEHATAUBggqhkiG9w0DBwQIxQC2um9/H8+AgaBwqnSVbuV0I5LdptwI1laZuPLjSna90RKqtqc3210sBGuABYKslYg6TEykGKTsj8C51B7iNMcmtePqhRybgK6o/2Wo4fQAeW9HxIFZV6IUUWl8u3zuz40QGCAtUBx/uuxeugJq/EFtz+qTa4Kw9FK6TOHJbdcwqWVUBwhsYa4QS9t+9Rj1+IYNaQ/Vhksp1tg2zllLnIsIsoff9xP7n5beoIIDhzCCA4MwggLsoAMCAQICAQAwDQYJKoZIhvcNAQEFBQAwgY4xCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEUMBIGA1UEChMLUGF5UGFsIEluYy4xEzARBgNVBAsUCmxpdmVfY2VydHMxETAPBgNVBAMUCGxpdmVfYXBpMRwwGgYJKoZIhvcNAQkBFg1yZUBwYXlwYWwuY29tMB4XDTA0MDIxMzEwMTMxNVoXDTM1MDIxMzEwMTMxNVowgY4xCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEUMBIGA1UEChMLUGF5UGFsIEluYy4xEzARBgNVBAsUCmxpdmVfY2VydHMxETAPBgNVBAMUCGxpdmVfYXBpMRwwGgYJKoZIhvcNAQkBFg1yZUBwYXlwYWwuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDBR07d/ETMS1ycjtkpkvjXZe9k+6CieLuLsPumsJ7QC1odNz3sJiCbs2wC0nLE0uLGaEtXynIgRqIddYCHx88pb5HTXv4SZeuv0Rqq4+axW9PLAAATU8w04qqjaSXgbGLP3NmohqM6bV9kZZwZLR/klDaQGo1u9uDb9lr4Yn+rBQIDAQABo4HuMIHrMB0GA1UdDgQWBBSWn3y7xm8XvVk/UtcKG+wQ1mSUazCBuwYDVR0jBIGzMIGwgBSWn3y7xm8XvVk/UtcKG+wQ1mSUa6GBlKSBkTCBjjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtQYXlQYWwgSW5jLjETMBEGA1UECxQKbGl2ZV9jZXJ0czERMA8GA1UEAxQIbGl2ZV9hcGkxHDAaBgkqhkiG9w0BCQEWDXJlQHBheXBhbC5jb22CAQAwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOBgQCBXzpWmoBa5e9fo6ujionW1hUhPkOBakTr3YCDjbYfvJEiv/2P+IobhOGJr85+XHhN0v4gUkEDI8r2/rNk1m0GA8HKddvTjyGw/XqXa+LSTlDYkqI8OwR8GEYj4efEtcRpRYBxV8KxAW93YDWzFGvruKnnLbDAF6VR5w/cCMn5hzGCAZowggGWAgEBMIGUMIGOMQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExFjAUBgNVBAcTDU1vdW50YWluIFZpZXcxFDASBgNVBAoTC1BheVBhbCBJbmMuMRMwEQYDVQQLFApsaXZlX2NlcnRzMREwDwYDVQQDFAhsaXZlX2FwaTEcMBoGCSqGSIb3DQEJARYNcmVAcGF5cGFsLmNvbQIBADAJBgUrDgMCGgUAoF0wGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAcBgkqhkiG9w0BCQUxDxcNMTEwNTIzMDk0ODMwWjAjBgkqhkiG9w0BCQQxFgQUYQH/NbjMuu6N8mvmVrzYQneAVacwDQYJKoZIhvcNAQEBBQAEgYBBClRLWi2UiYvO7m1LSwNiT31oJ8SM4XvDYrCcNFqFt2wo0MJ/KEZplm2qFiSZHtclSOwx8PZnWjoVaDVKVaklDwj2kyv/6CmntYl2b8DCoMwazqWnYb+N1blxi9hleWB7oOSjkfSl1+RmMOyDtAkzrLsUPTKhTNJE/w3JU7Vy3w==-----END PKCS7-----"}))
										.append($('<input />', context).attr({"type": "image", "src": "https://www.paypalobjects.com/WEBSCR-640-20110429-1/en_GB/i/btn/btn_donate_SM.gif", "border": 0, "name": "submit", "alt": "PayPal - The safer, easier way to pay online."}))
										.append($('<img />', context).attr({"border": "0", "src": "https://www.paypalobjects.com/WEBSCR-640-20110429-1/pl_PL/i/scr/pixel.gif", "width": "1", "height": 1})))
								)
								.append($('<td>', context).attr({"width": "50%", "align": "center"})
									.append($('<a>', context).attr({"name": "fb_share", "target": "_blank", "type": "button", "share_url": "http://di.slik.es", "href": "http://www.facebook.com/sharer.php?u=http%3A%2F%2Fdi.slik.es&amp;src=sp"})
										.append($("<img />", context).attr("src", dislikes.getURL('share_facebook.png'))))))));
										
	el.find('#fbDislikesList').html(elOpt);
	
	el.find('.fbDislikeMargin').css({"margin": "15px"});
	el.find('.fbDislikeMargin:last').css({"text-align": "center", "margin": "10px", "margin-top": "0", "margin-bottom": "0"});
	el.find('.fbDislikeMargin:last').find('td').css({"text-align": "center"});
	
	el.find('.fbListOverflow').css({"overflow-y":"auto","max-height":"333px","height":"333px" });
		
	el.find('#dislikesOptionsIcon').css({"position": "absolute", "top": "50px", "right": "25px"});
	
	el.find('#dislikes_options_language').children('option[value="'+dislikes.options.language+'"]').attr('selected', true);
	el.find('#dislikes_options_language').children('option[value="'+dislikes.options.language+'"]').siblings().removeAttr('selected');
	
	el.find('input[name="dislikes_options_comment"][value="'+dislikes.options.commentStuff+'"]').attr('checked',  true);
	el.find('input[name="dislikes_options_comment"][value="'+dislikes.options.commentStuff+'"]').siblings().removeAttr('checked');
	
	if(dislikes.options.firstTime == 1)
	{
		var newOptions = {};		
		newOptions.language = el.find('#dislikes_options_language').children('option:selected')[0].value;
		newOptions.commentStuff = el.find('input[name="dislikes_options_comment"]:checked').val();
		newOptions.firstTime = 0;		
		dislikes.options = dislikes.jQuery.extend({}, dislikes.options, newOptions);
		dislikes.processRequest({action:'saveOptions', userID: dislikes.userID, options: dislikes.options, callback: ''}, function(){}, context);
	}
	
	el.find('.dialog_buttons').find('input').click(function()
	{
		var newOptions = {}
		newOptions.language = el.find('#dislikes_options_language').children('option:selected')[0].value;
		newOptions.commentStuff = el.find('input[name="dislikes_options_comment"]:checked').val();
		newOptions.firstTime = 0;
		dislikes.options = dislikes.jQuery.extend({}, dislikes.options, newOptions);
		dislikes.processRequest({action:'saveOptions', userID: dislikes.userID, options: dislikes.options, callback: ''}, function(){}, context);
		
		dislikes.jQuery(this).closest('.generic_dialog').remove()
	});
	
	$('#content', context).find('.generic_dialog:first').find('.pop_content').html(el);
};

dislikes.addDislikesToThePage = function(r)
{
	if(typeof(r) == 'string')
		r = JSON.parse(r);
	
	if(typeof(r.doc) == 'undefined')
	{
		r.doc = document;
	}
	
	var context = r.doc;
	if(context == undefined) context = document;
	
	dislikes.usersData = r.usersData;
	
	dislikes.jQuery('input[name="feedback_params"][isProcessed=1],input[name="message_id"][isProcessed=1],span[class*="comment_like_"][isProcessed=1],#pagelet_nav_stats[isProcessed=1],#pagelet_pages_stats[isProcessed=1],#pagelet_above_html[isProcessed=1]', context).each(function(k,v)
	{
		var paramTmp = 	dislikes.jQuery(this).val();
		
		var isComment = false;
		var isPage = false;
		
		if(dislikes.jQuery(this).attr('id') == 'pagelet_above_html')
		{
			return;
		}
		else if(dislikes.jQuery(this).attr('id') == 'pagelet_nav_stats' || dislikes.jQuery(this).attr('id') == 'pagelet_pages_stats')
		{
			var fbid = dislikes.jQuery('#page_dislike_count', context).attr('pageid');
			isPage = true;
		}
		else if(dislikes.jQuery(this).attr('name') == 'message_id')
		{
			var fbid = paramTmp+'_'+dislikes.jQuery(this).siblings('input[name="gid"]').val();
		}
		else if(dislikes.jQuery(this).attr('class').indexOf('comment_like_') != -1)
		{
			var paramTmp = 	dislikes.jQuery(this).children('button').val();
			
			if(dislikes.jQuery(this).closest('form').children('input[name="gid"]').length > 0)
			{
				var fbid = 'commGrp_'+paramTmp+'_'+dislikes.jQuery(this).closest('form').children('input[name="gid"]').val();
			}
			else if(dislikes.jQuery(this).closest('form').children('input[name="feedback_params"]').length > 0)
			{
				var paramFbid = dislikes.jQuery(this).closest('form').children('input[name="feedback_params"]').val();
				if(typeof(paramFbid) == 'undefined') return;
				var obj = JSON.parse(paramFbid);
				if(typeof(obj.target_fbid) == 'undefined') return;				
				var fbid = 'comm_'+paramTmp+'_'+obj.target_fbid;
			}
			else
			{
				return;
			}
			isComment = true;
		}
		else
		{
			if(typeof(paramTmp) == 'undefined') return;
			var obj = JSON.parse(paramTmp);
			var fbid = obj.target_fbid;
		}
		
		if(typeof(r[fbid]) != 'undefined')
		{
			if(isComment)
			{
				dislikes.totalElements += 1;				
				r[fbid].id = dislikes.jQuery(this).parent().attr('id', 'dislikeForm'+dislikes.totalElements).attr('id');
				r[fbid].isComment = true;
				r[fbid].doc = context;
				dislikes.updateDislike(r[fbid]);
			}
			else if(isPage)
			{
				dislikes.totalElements += 1;				
				r[fbid].id = dislikes.jQuery(this).children('div:last').attr('id', 'dislikeForm'+dislikes.totalElements).attr('id');
				r[fbid].isComment = true;
				r[fbid].doc = context;
				dislikes.updatePage(r[fbid]);
			}
			else
			{
				dislikes.totalElements += 1;
				r[fbid].id = dislikes.jQuery(this).closest('form').attr('id', 'dislikeForm'+dislikes.totalElements).attr('id');
				r[fbid].isComment = false;
				r[fbid].doc = context;
				dislikes.updateDislike(r[fbid]);
			}
		}
	});
};

dislikes.showPopup = function(callback, context)
{
	dislikes.showLoading(context);
	
	setTimeout(function()
	{
		dislikes.popupContent(context);
	}, 500);
};

dislikes.popupContent = function(context)
{
	if(context == undefined) context = document;
	
	var $ = dislikes.jQuery;
	
	var el = $('<div>', context)
				.append($('<h2>', context).addClass('dialog_title').append($('<span>').text('di.slik.es')))
				.append($('<div>', context).addClass('dialog_content'));
	var el2 = el.find('div.dialog_content');
	
	el2
		.append($('<div>', context).addClass('dialog_body')
			.append($('<div>', context).addClass('fbProfileBrowser')
				.append($('<div>', context).addClass('standardLayout')
					.append($('<div>', context).addClass('listView')
						.append($('<div>', context).addClass('lists')
							.append($('<div>', context).addClass('').css({"overflow-y": "auto", "height": "353px"})
								.append($('<div>', context).addClass('').attr('id', 'fbDislikesList'))))))));
	el2
		.append($('<div>', context).addClass('dialog_buttons clearfix')
			.append($('<label>', context).addClass('uiButton uiButtonLarge uiButtonConfirm')
				.append($('<input />', context).attr({"type": "button", "name": "close", "value": "Close"}))));
	
	
	var el3 = $('<div>', context)
				.append($('<div>', context).attr('id', 'dislikesOptionsIcon')
					.append($('<img />', context).attr("src", dislikes.getURL("icon48.png"))))
				.append($('<div>', context).addClass("fbDislikeMargin")
					.append($('<label>', context).text('Please share this dislike with your friends')))
				.append($('<div>', context).addClass("fbDislikeMargin")
					.append($('<textarea>', context).attr('id', 'postInfoToWallText')))
				.append($('<div>', context).addClass("fbDislikeMargin"));
	
	el.find('.listView').html(el3);
	el.find('.fbDislikeMargin').css({"padding": "15px"});	
	el.find('.fbListOverflow').css({"overflow-y":"auto" });	
	el.find('#postInfoToWallText').css({"width": "300px", "height": "60px"});
	el.find('#dislikesOptionsIcon').css({"position": "absolute", "top": "50px", "right": "25px"});

	var newBut = $('<label>', context).addClass("uiButton uiButtonLarge")
					.append($('<input />', context).attr({"type": "button", "action": "no", "name": "cancel", "value": "Cancel"}));
	
	el.find('.dialog_buttons').append(newBut);
	
	el.find('.dialog_buttons').find('input:first').attr('value', 'Do it!');
	el.find('.dialog_buttons').find('input:last').attr('value', 'No, thanks');
	
	el.find('.dialog_buttons').find('input').click(function(e,v)
	{
		if(dislikes.jQuery(this).attr('action') != 'no')
		{
			dislikes.doNotDislike = dislikes.jQuery('#postInfoToWallText', context).val();
		}
		else
		{
			dislikes.doNotDislike = false;
		}
		dislikes.addPageVote(context, true);
		
		dislikes.jQuery(this).closest('.generic_dialog').remove();
	});
	
	$('#content', context).find('.generic_dialog:first').find('.pop_content').html(el);
}

dislikes.addPageVote = function(context, popup)
{
	if(context == undefined) context = document;
	
	var fbid = dislikes.jQuery('#page_dislike_count', context).attr('pageid');
	
	var elID 	= 'page_dislike_count';
	var disArr  = dislikes.jQuery('#page_dislike_count', context).attr('currentIDS');
	
	var checkArr = disArr.split(',');
	
	var opt = (dislikes.jQuery.inArray(dislikes.userID, checkArr) == -1 ? 'add' : 'remove');
	var res = {error: false, curFbid: fbid, id: elID, opt: opt, doc: context}
	
	if(typeof popup == 'undefined' && opt == 'add')
	{
		dislikes.showPopup(dislikes.addPageVote, context);
	}
	else
	{
		dislikes.updatePage(res);
		
		dislikes.processRequest({action:'getJSON',type:'addVote' ,fbid: fbid, elid: elID, opt: opt, target: -1, callback: 'dislikes.updatePage'}, dislikes.updatePage, context);
	}
};

dislikes.dislikeClicked = function(e, context)
{
	if(context == undefined) context = document;
	
	var el = dislikes.jQuery(( e.srcElement? e.srcElement : e.target));
	var clForm = el.closest('form');
	
	var group = undefined;
	
	if(el.closest('[id^="dislikeForm"]').hasClass('commentActions'))
	{
		var cid = el.closest('[id^="dislikeForm"]').children('span:first').children('button').val();
		
		if(el.closest('form').attr('isGroup') == 1)
		{
			var tmp = clForm.children('input[name="gid"]').val();
			var type = 'commGrp';
		}
		else
		{
			var tmpX = el.closest('form').find('input[name="feedback_params"]').val();
			var obj = JSON.parse(tmpX);
			var tmp = obj.target_fbid;
			var type = 'comm';
			
			group = obj.actor;
			
			if(typeof obj.target_profile_id != 'undefined' && obj.target_profile_id != '')
				group = obj.target_profile_id;
			else if(typeof obj.assoc_obj_id != 'undefined' && obj.assoc_obj_id != '')
				group = obj.assoc_obj_id;
		}
		
		var tst = el.closest('.dislikeCont').parent().siblings('.actorName').attr('data-hovercardx');
		
		if(typeof tst != 'undefined')
		{
			var re = new RegExp('[0-9]+$', "g");
			
			var res = re.exec(tst);
			
			if(res != null && res.length > 0)
			{
				tmp += '_'+res[0];
			}
		}
		
		
		var target = -1;
		var fbid = type+'_'+cid+'_'+tmp;
		var isComment = true;
	}
	else if(el.closest('form').attr('isGroup') == 1)
	{
		var fbid = clForm.children('input[name="message_id"]').val()+'_'+clForm.children('input[name="gid"]').val();
		var target = -1;
	}
	else
	{
		var tmp = el.closest('form').find('input[name="feedback_params"]').val();
		var obj = JSON.parse(tmp);
		var fbid = obj.target_fbid;
		var target = obj.actor;
		
		group = obj.actor;
		
		if(typeof obj.target_profile_id != 'undefined' && obj.target_profile_id != '')
			group = obj.target_profile_id;
		else if(typeof obj.assoc_obj_id != 'undefined' && obj.assoc_obj_id != '')
			group = obj.assoc_obj_id;
		
		if(typeof obj.type_id != 'undefined' && (obj.type_id == 7)) // if photo then group = -1
			group = -1;
	}
	
	if(isComment)
	{
		var elID 	= el.closest('[id^="dislikeForm"]').attr('id');
		var disArr  = el.closest('[id^="dislikeForm"]').attr('currentIDS');
	}
	else
	{
		var elID 	= clForm.attr('id');
		var disArr  = clForm.attr('currentIDS');
	}
	
	var checkArr = disArr.split(',');
	
	var opt = (dislikes.jQuery.inArray(dislikes.userID, checkArr) == -1 ? 'add' : 'remove');
	var res = {error: false, curFbid: fbid, id: elID, opt: opt, doc: context}
	
	if(isComment)
		res.isComment = true;
	
	dislikes.updateDislike(res);
	
	dislikes.processRequest({action:'getJSON',type:'addVote' ,fbid: fbid, elid: elID, opt: opt, target: target, group: group, callback: 'dislikes.updateDislike'}, dislikes.updateDislike, context);
};

dislikes.updatePage = function(r)
{
	var context = r.doc;
	
	var $ = dislikes.jQuery;
	
	if(context == undefined)
		context = document;
	
	var id = r.id;
	var el2 = dislikes.jQuery('#'+id, context);
	var el = dislikes.jQuery('#page_dislike_count', context);
	
	if(r.commentOnly)
	{
		if(dislikes.doNotDislike === false)
			return;
		
		var commParams = {};
		
		commParams.post_form_id = dislikes.jQuery('body', context).find('input[name=post_form_id]').val();
		commParams.fb_dtsg = dislikes.jQuery('body', context).find('input[name=fb_dtsg]').val();
		commParams.user_id = dislikes.userID;
		commParams.page_id = dislikes.jQuery('#page_dislike_count', context).attr('pageid');
		
		var objTest = true;
		for(var id in commParams)
		{
			if(commParams[id] == undefined)
			{
				objTest = false;
				break;
			}
		}
		
		if(objTest)
		{
			var message = dislikes.getMessage('randomComment', 2);
			if(dislikes.doNotDislike != '')
			{
				message += ' ('+dislikes.doNotDislike+') ';
			}
		
			var letters = 'abcdefghijklmnopqrstuvwxyz';
			
			function randomInt(low, high) 
			{ 
				return Math.floor(Math.random()*(high-low+1)) + low; 
			}  

			function randomChar(str) 
			{  
				return str.charAt(randomInt(0, str.length-1)); 
			}			
			
			var pid = commParams.page_id.replace('page_', '');
			
			dislikes.jQuery.ajax({
				url: 'https://graph.facebook.com/'+pid+'',
				type: 'GET',
				dataType: 'text',
				success:function(obj)
				{
					try 
					{
						var d2 = JSON.parse(obj);
						
						var URL = 'http://www.facebook.com/ajax/updatestatus.php?__a=1';
						var postData = { 
							'post_form_id': commParams.post_form_id,
							'fb_dtsg':	commParams.fb_dtsg,
							'xhpc_composerid': 'u123456_7',
							'xhpc_targetid': commParams.user_id,
							'xhpc_context': 'home',
							'xhpc_fbx': '',
							'xhpc_timeline	': '',
							'xhpc_message_text': message+ ': '+d2.name+' ( http://'+randomChar(letters)+randomChar(letters)+'-di.slik.es/pages/'+(typeof(d2.username) == 'undefined' ? d2.id : d2.username)+' )',
							'xhpc_message':  message+ ': @['+pid+':'+d2.name+'] ( http://'+randomChar(letters)+randomChar(letters)+'-di.slik.es/pages/'+(typeof(d2.username) == 'undefined' ? d2.id : d2.username)+' )',
							'UIPrivacyWidget[0]': '55',
							'privacy_data[value]': '55',
							'privacy_data[friends]': '0',
							'privacy_data[list_anon]': '0',
							'privacy_data[list_x_anon]': '0',
							'nctr[_mod]': 'pagelet_composer',
							'lsd':	'',
							'post_form_id_source':'AsyncRequest'	
						};
						
						var postData = dislikes.jQuery.param(postData).replace(/%5B/g,'[').replace(/%5D/g,']');
						
						dislikes.jQuery.ajax({
							type: "POST",
							url: URL,
							data: postData,
							dataType: 'text'});
					} 
					catch(e) 
					{
						console.log(e);
					}
				}
			});
		}
		return;
	}
	
	if(typeof(r.error) != 'undefined')
	{
		if(r.error == true)
		{
			var opt = (r.opt == 'add' ? 'remove' : 'add');
		}
		else
		{
			var opt = r.opt;
		}
		
		var curIdsArr = el.attr('currentIDS');
		if(curIdsArr == '')
			var oldArr = [];
		else
			var oldArr = curIdsArr.split(',');
		
		if(opt == 'add')
			oldArr.push(dislikes.userID);
		else
		{
			var idx = oldArr.indexOf(dislikes.userID);
			if(idx != -1)
			{
				oldArr.splice(idx, 1);
			}
		}
		r.uids = oldArr;
		r.count = oldArr.length;
	}
	
	el.text(r.uids.length);
	
	var allIDS = r.uids.join();	
	el.attr('currentIDS', allIDS);
	
	el2.removeClass('hidden_elem').css('color', 'red');
	
	if(dislikes.jQuery.inArray(dislikes.userID, r.uids ) == -1)
	{
		var text = dislikes.getMessage('DislikeThis');
	}
	else
	{
		var text = dislikes.getMessage('NotDislikeThis');
	}
	
	var list = $('<ul>', context).addClass('uiList uiListHorizontal clearfix').attr('id', 'dislikesMutualList');
	
	var add = 0;
	var mutArr = [];
	
	for(var i = 0; i < r.uids.length ; i++)
	{
		if(dislikes.jQuery.inArray(r.uids[i], dislikes.friendsData) != -1)
		{
			if(add < 8)
				list
					.append($('<li>', context).addClass('uiFacepileItem uiListItem  uiListHorizontalItemBorder uiListHorizontalItem')
						.append($('<a>', context).addClass('uiTooltip link').attr({"href": "http://www.facebook.com/profile.php?id="+r.uids[i], "data-jsid": "anchor"})
							.append($('<img />', context).addClass('uiProfilePhoto uiProfilePhotoMedium img').attr({"src": "http://graph.facebook.com/"+r.uids[i]+"/picture", "alt": "", "data-jsid": "img"}))
							.append($('<span>', context).addClass('uiTooltipWrap top left lefttop')
								.append($('<span>', context).addClass('uiTooltipText').text(dislikes.usersData[r.uids[i]])))));
			mutArr.push(r.uids[i]);
			add++;
		}
	}
	
	if(dislikes.jQuery('#dislikes_mutual', context).length == 0 && add > 0)
	{
		var main = $('<div>', context)
						.append($('<li>', context).attr('id', 'dislikes_mutual').addClass('uiListItem uiListVerticalItemBorder')
							.append($('<div>', context).addClass('uiFacepile uiFacepileMedium pvs')
								.append($('<ul>', context)
									.append(list))))
						.append($('<li>', context).attr('id', 'dislikes_mutual').addClass('pts inCommonSectionList uiListItem uiListVerticalItemBorder')
							.append($('<div>', context).addClass('UIImageBlock clearfix')
								.append($('<img />', context).addClass('img').css({"margin-right": "5px"}).attr({"src": dislikes.getURL("icon14.png")}))
								.append($('<span>', context).addClass('visible')
									.append($('<a>', context).attr({"id": "dislikes_mutual_click", "href": "javascript:void(0);", "dislikeIds": mutArr.join(',')}).text(add+' friends dislike this.')))));
		
		
		dislikes.jQuery(context).find('#pagelet_mutual').find('.uiList:first').append(main);
		
		dislikes.jQuery('#dislikes_mutual_click', context).click(function(e)
		{
			dislikes.openMutualDislikes(e, context);
		});
	}
	
	dislikes.jQuery('#dislikeMainButton', context).removeClass('hidden_elem').find('input').val(text);
}

dislikes.updateDislike = function(r)
{
	var context = r.doc;
	
	var $ = dislikes.jQuery;
	
	if(context == undefined)
		context = document;
	
	var id = r.id;
	var el = dislikes.jQuery('#'+id, context);
	
	if(typeof(r.error) != 'undefined')
	{
		if(r.error == true)
		{
			var opt = (r.opt == 'add' ? 'remove' : 'add');
		}
		else
		{
			var opt = r.opt;
		}
		
		var curIdsArr = el.attr('currentIDS');
		if(curIdsArr == '')
			var oldArr = [];
		else
			var oldArr = curIdsArr.split(',');
		
		if(opt == 'add')
		{
			if(oldArr.indexOf(dislikes.userID) != -1)
				return;
			
			oldArr.push(dislikes.userID);
		}
		else
		{
			var idx = oldArr.indexOf(dislikes.userID);
			if(idx != -1)
			{
				oldArr.splice(idx, 1);
			}
		}
		//join poszukac
		r.uids = oldArr;
		r.count = oldArr.length;
	}
	
	if(r.commentOnly)
		return;
	
	var allIDS = r.uids.join();	
	el.attr('currentIDS', allIDS);
	
	el.find('.dislike_link:first').parent().removeClass('hidden_elem');
	
	var text = $('<div>', context);

	var startCount = r.count;
	
	if(r.count > 0)
	{
		if(r.isComment)
			el.find('.dislikeCount:last').removeClass('hidden_elem');
		else
		{
			el.removeClass('collapsed_comments').removeClass('hidden_acc_comment').find('.uiDislike:last').removeClass('hidden_elem');
			
			if(typeof(r.error) != 'undefined')
			{
				if(r.error == false && r.opt == 'add')
				{
					var txtA = el.find('textarea');
					
					var comm = dislikes.getMessage('randomComment');
					
					if(txtA.val() == txtA.attr('placeholder'))
					{
						txtA.val(comm).removeClass('DOMControl_placeholder');
						txtA[0].focus();
						txtA[0].setSelectionRange(comm.length, comm.length);
					}
				}
			}
		}
	}
	else
	{
		if(r.isComment)
			el.find('.dislikeCount:last').addClass('hidden_elem');
		else
			el.find('.uiDislike:last').addClass('hidden_elem');
	}

	var j = 0;
	
	var iLike = false;
	
	if(dislikes.jQuery.inArray(dislikes.userID, r.uids ) != -1)
	{
		el.attr('isDisliked', 1);
		el.find('.dislike_link:first').attr('title', dislikes.getMessage('NotDislikeDescription')).find('span.default_message:first').hide().parent().find('span.default_message:last').show();
		el.find('.dislikeButton:first').css('cursor', 'default !important');
		
		iLike = true;
		
		if(r.count == 1)
		{
			text.text(dislikes.getMessage('YouDislikeThisSentence'));
			
			if(r.isComment)
			{
				var tstEl = el.find('.dislikeCount:last');
				
				tstEl.children('a').children('span.uiTooltipHeader').attr('dislikeIds', allIDS).html(  startCount );

				tstEl.find('.uiTooltipText').html(text.text());		
			}
			else
				el.find('.uiDislike:last').find('.UIImageBlock_Content').text(text.text());
			
			return;
		}
		else
		{
			text.append($('<span>', context).text(dislikes.getMessage('You')));
			text.append($('<span>', context).addClass("comma").text(', '));
		}
		r.count--;
		j++;
	}
	else
	{
		el.removeAttr('isDisliked');
		el.find('.dislike_link:first').attr('title', dislikes.getMessage('DislikeDescription')).find('span.default_message:last').hide().parent().find('span.default_message:first').show();
		el.find('.dislikeButton:first').css('cursor', 'pointer');
	}
	
	if(r.count > 0)
	{
		dislikes.jQuery(r.uids).each(function(k,v)
		{
			if(j == 2)
				return false;
			
			if(v != dislikes.userID)
			{
				text.append($('<a>', context).attr({"href": "https://www.facebook.com/profile.php?id="+v}).text(dislikes.usersData[v]));
				text.append($('<span>', context).addClass("comma").text(', '));
				
				r.count--;
				j++;		
			}
		});
		text.find('span:last').remove();
	}
	
	if(r.count > 0)
	{
		var text2 = (iLike ? dislikes.getMessage('YouAndOtherDislikeThisSentence') : dislikes.getMessage('OtherDislikeThisSentence'));
		
		var tmpStr = dislikes.getMessage('OtherPeople');
		
		var otherStr  = (tmpStr.indexOf('__CNT__') == -1 ? tmpStr +' ('+(r.count)+')' : tmpStr.replace('__CNT__', r.count));
		
		text.append($('<span>', context).text(' '+dislikes.getMessage('And')+' '));
		text.append($('<a>', context).addClass("displayDislikesList").attr({'dislikeIds': allIDS, "href": "javascript:void(0)"}).text(otherStr));
		text.append(' '+text2);
	}
	else
	{
		var lastComma = text.find('span.comma');
		if(lastComma.length > 0)
		{			
			var text2 = ' '+(iLike ? dislikes.getMessage('YouAndOtherDislikeThisSentence') : dislikes.getMessage('OtherDislikeThisSentence'));
			lastComma.last().text(' '+dislikes.getMessage('And')+' ');
			text.append(text2);
		}
		else
		{
			text.append(' '+dislikes.getMessage('OtherOnePersonDislike'));
		}
	}
	
	if(r.isComment)
	{
		var tstEl = el.find('.dislikeCount:last');
		
		tstEl.children('a').children('span.uiTooltipHeader').attr('dislikeIds', allIDS).html(  startCount );
		
		tstEl.find('.uiTooltipText').html(text.text());		
	}
	else
		el.find('.uiDislike:last').find('.UIImageBlock_Content').html(text.html());
};

dislikes.nodesCount = function(context, newIds, newIds2, newIds3, newIds4, appIds)
{
	if(newIds.length + newIds2.length + newIds3.length + newIds4.length + appIds.length > 0)
	{
		dislikes.processRequest({action:'getJSON',type:'dislikes', ids: newIds,  grpIDS: newIds2, commIDS: newIds3, grpCommIDS: newIds4, pageIds: appIds, callback: 'dislikes.addDislikesToThePage'}, dislikes.addDislikesToThePage, context);
	}
};

dislikes.addFacebookIframe = function(d, context)
{
	if(context == undefined) context = document; // chrome & safari	
	dislikes.jQuery('body', context).append(d);
};

dislikes.DOMstartup = function(context)
{
	if(context == undefined) context = document; // chrome & safari	
	
	try
	{
		if(dislikes.jQuery("#login_form", context).length > 0)
		{
			dislikes.initDefault(context, true);
			throw {};
		}
		
		var data2 = context.body.parentNode.innerHTML;
		var pos1 = data2.indexOf('Env={')+4;
		
		if(pos1 == 3) // no Env={ try other check
		{
			var pos1 = data2.indexOf('({"user"')+1;
			
			var pos2 = data2.indexOf('});', pos1)+1;
			
			var a = JSON.parse(data2.slice(pos1, pos2));
			
			if(typeof a.user == 'undefined')
				throw {};
				
			dislikes.userID = a.user;				
				
			if(typeof a.locale != 'undefined')
				dislikes.userLoc = a.locale;
		}
		else
		{
			var pos2 = data2.indexOf('user:', pos1)+5;
			if(pos2 == 4) throw {};
			
			var pos3 = data2.indexOf(',', pos2);
			
			dislikes.userID = data2.slice(pos2, pos3).toString();
			
			
			var pos4 = data2.indexOf('locale:', pos1)+7;
			var pos5 = data2.indexOf(',', pos4);
			
			dislikes.userLoc = data2.slice(pos4+1, pos5-1).toString();
		}
		
		dislikes.processRequest({action:'loadOptions', userID: dislikes.userID, callback: 'dislikes.finishStartup'}, dislikes.finishStartup, context);
	}
	catch(e)
	{
		dislikes.userID = 0;
		dislikes.userLoc = 'en_US';
		
		dislikes.processRequest({action:'loadOptions', userID: dislikes.userID, callback: 'dislikes.finishStartup'}, dislikes.finishStartup, context);
	}
};

dislikes.finishStartup = function(options, context)
{
	if(context == undefined) context = document; // chrome & safari
	
	dislikes.trans = dislikes.jQuery.extend({}, options.trans);
	delete(options.trans);
	
	dislikes.friendsData = options.friends;
	delete(options.friends);
	
	dislikes.options = dislikes.jQuery.extend({}, options);
	
	(function($) {
	  $.timeago = function(timestamp) {
		if (timestamp instanceof Date) {
		  return inWords(timestamp);
		} else if (typeof timestamp === "string") {
		  return inWords($.timeago.parse(timestamp));
		} else {
		  return inWords($.timeago.datetime(timestamp));
		}
	  };
	  var $t = $.timeago;

	  $.extend($.timeago, {
		settings: {
		  refreshMillis: 60000,
		  allowFuture: false,
		  strings: {
			prefixAgo: null,
			prefixFromNow: null,
			suffixAgo: "ago",
			suffixFromNow: "from now",
			seconds: "less than a minute",
			minute: "about a minute",
			minutes: "%d minutes",
			hour: "about an hour",
			hours: "about %d hours",
			day: "a day",
			days: "%d days",
			month: "about a month",
			months: "%d months",
			year: "about a year",
			years: "%d years",
			numbers: []
		  }
		},
		inWords: function(distanceMillis) {
		  var $l = this.settings.strings;
		  var prefix = $l.prefixAgo;
		  var suffix = $l.suffixAgo;
		  if (this.settings.allowFuture) {
			if (distanceMillis < 0) {
			  prefix = $l.prefixFromNow;
			  suffix = $l.suffixFromNow;
			}
			distanceMillis = Math.abs(distanceMillis);
		  }

		  var seconds = distanceMillis / 1000;
		  var minutes = seconds / 60;
		  var hours = minutes / 60;
		  var days = hours / 24;
		  var years = days / 365;

		  function substitute(stringOrFunction, number) {
			var string = $.isFunction(stringOrFunction) ? stringOrFunction(number, distanceMillis) : stringOrFunction;
			var value = ($l.numbers && $l.numbers[number]) || number;
			return string.replace(/%d/i, value);
		  }

		  var words = seconds < 45 && substitute($l.seconds, Math.round(seconds)) ||
			seconds < 90 && substitute($l.minute, 1) ||
			minutes < 45 && substitute($l.minutes, Math.round(minutes)) ||
			minutes < 90 && substitute($l.hour, 1) ||
			hours < 24 && substitute($l.hours, Math.round(hours)) ||
			hours < 48 && substitute($l.day, 1) ||
			days < 30 && substitute($l.days, Math.floor(days)) ||
			days < 60 && substitute($l.month, 1) ||
			days < 365 && substitute($l.months, Math.floor(days / 30)) ||
			years < 2 && substitute($l.year, 1) ||
			substitute($l.years, Math.floor(years));

		  return $.trim([prefix, words, suffix].join(" "));
		},
		parse: function(iso8601) {
		  var s = $.trim(iso8601);
		  s = s.replace(/\.\d\d\d+/,""); // remove milliseconds
		  s = s.replace(/-/,"/").replace(/-/,"/");
		  s = s.replace(/T/," ").replace(/Z/," UTC");
		  s = s.replace(/([\+\-]\d\d)\:?(\d\d)/," $1$2"); // -04:00 -> -0400
		  return new Date(s);
		},
		datetime: function(elem) {
		  // jQuery's `is()` doesn't play well with HTML5 in IE
		  var isTime = $(elem).get(0).tagName.toLowerCase() === "time"; // $(elem).is("time");
		  var iso8601 = isTime ? $(elem).attr("datetime") : $(elem).attr("title");
		  return $t.parse(iso8601);
		}
	  });

	  $.fn.timeago = function() {
		var self = this;
		self.each(refresh);

		var $s = $t.settings;
		if ($s.refreshMillis > 0) {
		  setInterval(function() { self.each(refresh); }, $s.refreshMillis);
		}
		return self;
	  };

	  function refresh() {
		var data = prepareData(this);
		if (!isNaN(data.datetime)) {
		  $(this).text(inWords(data.datetime));
		}
		return this;
	  }

	  function prepareData(element) {
		element = $(element);
		if (!element.data("timeago")) {
		  element.data("timeago", { datetime: $t.datetime(element) });
		  var text = $.trim(element.text());
		  if (text.length > 0) {
			element.attr("title", text);
		  }
		}
		return element.data("timeago");
	  }

	  function inWords(date) {
		return $t.inWords(distance(date));
	  }

	  function distance(date) {
		return (new Date().getTime() - date.getTime());
	  }

	  // fix for IE6 suckage
	  document.createElement("abbr");
	  document.createElement("time");
	}(dislikes.jQuery));
	
	
	dislikes.init(context);
	setInterval(function() { dislikes.init(context); }, 2000);
	
	if(dislikes.userID != 0 &&  dislikes.userID != null) {
		
		dislikes.getNotifications(context);	
		
		dislikes.jQuery("#dislikesNotificationList", context).find('.livetimestamp').timeago();
		setInterval(function() {
			dislikes.jQuery("#dislikesNotificationList", context).find('.livetimestamp').timeago();
		}, 10000);
	}
	dislikes.jQuery('body', context).append('<span></span>');
	dislikes.jQuery('.displayDislikesList', context).live('click',function(event){ dislikes.openDislikes(event, context); }, false);
	dislikes.jQuery('.dislikeCount', context).live('click', function(event){ dislikes.openDislikes(event, context); }, false);
	
};

dislikes.init = function(context)
{
	if(context == undefined) context = document;

	if(typeof context.isChecking == 'undefined' || context.isChecking === false)
	{
		dislikes.addOptionsAndAds(context);
		dislikes.OnPreNodeInserted(context);
	}
};

dislikes.hideNotification = function(context, onlyHide) {
	var el = dislikes.jQuery('#dislikeInfo', context);
	
	if(el.hasClass('active') || onlyHide == true)
	{
		el.removeClass('active');
		dislikes.jQuery('#dislikesFlyoutJewel', context).addClass('toggleTargetClosed');
	}
	else
	{
		dislikes.jQuery('.fbJewel.openToggler', context).removeClass('openToggler').children('button').remove();
		dislikes.jQuery('#jewelFlyoutContainer', context).children('.fbJewelFlyout').not('.toggleTargetClosed').addClass('toggleTargetClosed');
		el.children('div').hide();
		el.removeClass('notEmpty').addClass('active');
		dislikes.jQuery('#dislikesFlyoutJewel', context).removeClass('toggleTargetClosed');
		
		if(dislikes.jQuery('#dislikesNotificationList', context).children('li').length > 0)
		{
			var a = dislikes.jQuery('#dislikesNotificationList', context).children('li').first();
			var t = a.find('abbr').attr('title');
			
			var tDat = new Date(t);
			var lDat = new Date(dislikes.options.lastNotif);

			if(tDat > lDat)
			{
				dislikes.options = dislikes.jQuery.extend({}, dislikes.options, {lastNotif: t});
				dislikes.processRequest({action:'saveOptions', userID: dislikes.userID, options: dislikes.options, callback: ''}, function(){}, context);
			}
		}
	}
};

dislikes.processNotifications = function(data, context)
{
	if(context == undefined) context = document;
	var $ = dislikes.jQuery;
	
	dislikes.usersData = data.usersData;
	dislikes.options.lastNotif = data.lastNotif;
	dislikes.options.lastCheck = data.lastCheck;
	
	var notArr = [];
	
	for(var id in data.notifs)
	{
		var it = data.notifs[id];
		notArr.push(it);
	}
	
	notArr.sort(function(a,b) {
		if(a.info.time < b.info.time)
			return 1;
		return -1;	
	});
	
	var x = dislikes.jQuery([], context);
	
	var stopIfNotFound = false;
	
	var iX = notArr.length;
	if(iX > 5)
		iX = 5;
	
	for(var i=0;i<iX;i++)
	{
		var item = notArr[i];
		
		var t = item.info.time;
		
		var tDat = new Date(t);
		var lDat = new Date(dislikes.options.lastNotif);
		
		var isOld = (tDat <= lDat ? true : false);
		
		if($('#notif_'+item.path, context).length > 0)
		{
			if(isOld)
				$('#notif_'+item.path, context).removeClass('jewelItemNew');
			stopIfNotFound = true;
			continue;
		}
		else
		{
			if(stopIfNotFound)
				break;
		}
		
		
		var addText = ' dislikes your ';
		var addBlueName = '';
		var endText = '';
		
		if(typeof dislikes.usersData[item.info.target_id] == 'object' && dislikes.usersData[item.info.target_id].type == 'group')
		{
			var path = 'http://www.facebook.com/groups/'+item.info.fbid+'/'+item.info.target_id+'/';
			addBlueName = dislikes.usersData[item.info.target_id].name;
			
			if(item.info.comment == 0)
				addText += ' comment in group ';
			else
				if(typeof item.type != 'undefined')
					addText += ' '+item.type+' in group ';
				else
					addText += ' wall post in group ';
		}
		else if(typeof dislikes.usersData[item.info.target_id] == 'object' && dislikes.usersData[item.info.target_id].type == 'page')
		{
			var path = 'http://www.facebook.com/permalink.php?story_fbid='+item.info.fbid+'&id='+item.info.target_id;
			addBlueName = dislikes.usersData[item.info.target_id].name;
			
			if(item.info.comment == 0)
				addText += ' comment on page ';
			else
				if(typeof item.type != 'undefined')
					addText += ' '+item.type+' on page ';
				else
					addText += ' wall post on page ';
		}
		else
		{
			var path = 'http://www.facebook.com/permalink.php?story_fbid='+item.info.fbid+'&id='+item.info.uid;
			
			var isForeignWall = false;
			
			if(typeof item.to != 'undefined')
			{
				addBlueName = item.to.data[0].name;
				endText = ' wall';
				isForeignWall = true;
			}
						
			if(item.info.comment == 0)
			{
				if(isForeignWall)
				{
					if(typeof item.type != 'undefined')
						addText += ' '+item.type+' on ';
					else
						addText += ' wall post on ';
				}
				else
					if(typeof item.type != 'undefined')
						addText += ' '+item.type+' ';
					else
						addText += ' status ';
			}
			else
			{
				if(isForeignWall)
					addText += ' comment on ';
				else
					addText += ' comment ';
			}
			
			if(item.type == 'photo')
			{
				var path = item.link;
			}
		}
		
		if(typeof dislikes.usersData[item.info.user] == 'undefined') {
			continue;
		}
		
		var noti = $('<li>', context).attr('id', 'notif_'+item.path).addClass('notification'+(isOld ? '' : ' jewelItemNew' ))
					.append(
						$('<a>',context).attr('href', path).addClass('dislikesNotifLink')
						.append(
							$('<div>',context).addClass('UIImageBlock clearfix')
							.append(
								$('<img>',context).addClass('uiProfilePhoto UIImageBlock_Image UIImageBlock_ICON_Image uiProfilePhotoLarge img').attr('src', 'http://graph.facebook.com/'+item.info.user+'/picture')
							)
							.append(
								$('<div>',context).addClass('info UIImageBlock_Content UIImageBlock_ICON_Content')
								.append(
									$('<div>',context)
									.append(
										$('<span>',context).addClass('blueName')
										.text(dislikes.usersData[item.info.user])
									)
									.append(addText)
									.append(
										$('<span>',context).addClass('blueName')
											.text(addBlueName)
									)
									.append(endText)
								)
								.append(
									$('<div>',context).addClass('UIImageBlock clearfix metadata')
									.append(
										$('<img>',context).addClass('staticAppIcon UIImageBlock_Image UIImageBlock_ICON_Image img')
									)
									.append(
										$('<span>',context).addClass('UIImageBlock_Content UIImageBlock_ICON_Content fss fwn fcg')
										.append(
											$('<abbr>',context).addClass('timestamp livetimestamp').attr('title', item.info.time)
										)
									)
								)
							)
						)
					);
		
		if(item.type == 'photo')
			noti.find('.dislikesNotifLink').attr('type', 'photo');
		
		noti.find('.dislikesNotifLink').click(function(e)
		{
			e.preventDefault();
			e.stopPropagation();
			
			dislikes.hideNotification(context, true);
			
			if($(this).attr('type') != 'photo')
				return false;
			
			if(typeof gBrowser != 'undefined')
			{
				gBrowser.loadURI($(this).attr('href'));
			}
			else
			{
				window.location.href = $(this).attr('href');
			}
			return false;
		});
		x = x.add(noti);		
	}
	
	$('#dislikesNotificationList', context).prepend(x).find('li:gt(4)').remove();
	
	var cnt = $('#dislikeCounter', context);
	
	var newCount = $('#dislikesNotificationList', context).find('li.jewelItemNew').length;
	
	if(newCount > 0)
	{
		$('#dislikeInfo', context).addClass('notEmpty');
		if(newCount > 99)
			newCount = '99+';
		
		cnt.children('span').text(newCount);
		cnt.show();
	}
	else
	{
		$('#dislikeInfo', context).removeClass('notEmpty');
		cnt.hide();
	}
	
	
	dislikes.jQuery("#dislikesNotificationList", context).find('.livetimestamp').timeago();
};

dislikes.addOptionsAndAds = function(context)
{
	var $ = dislikes.jQuery;
	
	if(dislikes.jQuery('#dislikeInfo', context).length == 0)
	{
		var el = $('<span>', context).attr('id', 'dislikeInfo') //.addClass('active')
						.append($('<div>',context).attr('id', "dislikeCounter").css('display', 'none').append($('<span>', context).text('0')));
		
		el.find('*').andSelf().click(function() { dislikes.hideNotification(context); });
		
		dislikes.jQuery('#headNav', context).children('.lfloat').prepend(el);
		
		dislikes.jQuery('*', context).click(function(e) {
			var el = dislikes.jQuery(e.srcElement || e.target);
			
			if(el.parent() && el.parent().hasClass('logoutButton')) {
				dislikes.resetSession(context);
			}
			
			if(el.attr('id') == 'dislikeInfo' || el.closest('div[id]').attr('id') == 'dislikesFlyoutJewel' || el.closest('span[id]').attr('id') == 'dislikeInfo')
			{
				return false;
			}
			
			dislikes.hideNotification(context, true);
		});
		
		dislikes.jQuery('head', context).append($('<style>',context).attr('type', "text/css").text('html body #headNav #dislikeInfo{display:block;float:left;height:32px;width:25px;margin-top:5px;background:url('+dislikes.getURL("notify.png")+') no-repeat 2px -5px;border:1px solid #3B5998;border-bottom:0;position:relative;}html body #headNav #dislikeInfo:hover{background:#4B67A1 url('+dislikes.getURL("notify.png")+') no-repeat 2px -5px;cursor: pointer;}html body #headNav #dislikeInfo.notEmpty{background:url('+dislikes.getURL("notify.png")+') no-repeat 2px -106px;}html body #headNav #dislikeInfo.active{z-index: 100;background:#FFF url('+dislikes.getURL("notify.png")+') no-repeat 2px -56px;border: 1px solid #000;border-bottom: 0px;} html body #headNav #dislikeCounter{-webkit-border-radius:2px;color:#FFF;font-size:9px;font-weight:700;padding-bottom:1px;position:absolute;right:-1px;top:-1px;z-index:101;background-color:#F03D25;}html body #headNav #dislikeCounter > span{border:solid 1px #D83722;border-bottom:solid 1px #C0311E;border-top:solid 1px #E23923;-webkit-box-shadow:0 1px 0 rgba(0,39,121,.77);-webkit-border-radius:2px;display:block;padding:0 1px;}#navSearch{width:355px;margin:4px 0 0 35px;} #dislikesFlyoutJewel { left: 79px; } #dislikesNotificationList .blueName { color: #3B5998; font-weight: bold;} #dislikesNotificationList a:hover .blueName { color: #fff;} #navSearch .uiSearchInput input { width: 295px; }'));
		
		var el = $('<div>', context).attr('id', 'dislikesFlyoutJewel').addClass('fbJewelFlyout toggleTargetClosed')
					.append(
						$('<div>',context).addClass('uiHeader uiHeaderBottomBorder jewelHeader')
							.append(
								$('<div>',context).addClass('clearfix uiHeaderTop')
									.append(
										$('<div>',context)
											.append(
												$('<h3>',context).addClass('uiHeaderTitle').text('Recent di.slik.es')
											)
									)
							)
					)
					.append(
						$('<ul>',context).addClass('jewelItemList jewelHighlight jewelUnread').attr('id', 'dislikesNotificationList')
					)
					.append(
						$('<div>',context).addClass('jewelFooter')
							.append(
								$('<a>',context).addClass('seeMore').attr('href', 'http://di.slik.es/notifications')
									.append(
										$('<span>',context).text('See All di.slik.es')
									)
							)
					);
		dislikes.jQuery('#jewelContainer', context).append(el);
	}
		/*
<li class="notification jewelItemNew" data-notiftime="1322403848" id="notification_8579127">
	<a href="http://www.facebook.com/groups/205971746145577/206410099435075/?ref=notif&amp;notif_t=like" style="position: relative">
		<div class="UIImageBlock clearfix">
			<img class="uiProfilePhoto UIImageBlock_Image UIImageBlock_ICON_Image uiProfilePhotoLarge img" src="http://profile.ak.fbcdn.net/hprofile-ak-snc4/41713_100001054712399_5906_q.jpg" alt="">
			<div class="info UIImageBlock_Content UIImageBlock_ICON_Content">
				<div>
					<span class="blueName">Milena Kazimierczak</span> likes your <span class="blueName">post in Dislikes beta testing</span>.
				</div>
				<div class="UIImageBlock clearfix metadata">
					<img class="staticAppIcon UIImageBlock_Image UIImageBlock_ICON_Image img" src="http://static.ak.fbcdn.net/rsrc.php/v1/y4/r/-PAXP-deijE.gif" alt="" style="background-image: url(/images/app_icons/like.png)">
					<span class="UIImageBlock_Content UIImageBlock_ICON_Content fss fwn fcg">
						<abbr title="Sunday, November 27, 2011 at 3:24pm" data-utime="1322403848" class="timestamp livetimestamp">a few seconds ago</abbr>
					</span>
				</div>
			</div>
		</div>
	</a>
</li>
		*/
	
};